home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / wasm223.zip / BUFFER4.ASM < prev    next >
Assembly Source File  |  1993-05-05  |  2KB  |  88 lines

  1. ;*************************************;
  2. ; WASM Buffered File I/O, Token Input ;
  3. ; By Eric Tauck                       ;
  4. ;                                     ;
  5. ; Defines:                            ;
  6. ;                                     ;
  7. ;   GetTok  input a token             ;
  8. ;                                     ;
  9. ; Requires:                           ;
  10. ;                                     ;
  11. ;   BUFFER2.ASM                       ;
  12. ;*************************************;
  13.  
  14.         jmps    _buffer4_end
  15.  
  16. ;========================================
  17. ; Read a token delimited by spaces or
  18. ; control-characters.
  19. ;
  20. ; In: AX= storage area; CX= max length;
  21. ;     BX= buffer record.
  22. ;
  23. ; Out: AX= length of token (zero if
  24. ;      none); CY= set if error (AX=0 if
  25. ;      token too long, AX= error code if
  26. ;      read error); EOF returns a zero
  27. ;      length token but no error.
  28.  
  29. GetTok  PROC    NEAR
  30.         push    di
  31.         mov     di, ax
  32.  
  33.         push    di              ;save to length calculation
  34.  
  35. ;--- skip delimiters
  36.  
  37. _gttok1 push    cx
  38.         call    GetByt          ;read a character
  39.         pop     cx
  40.         jc      _gttok5         ;jump if error
  41.         cmp     al, 32          ;lower range of valid characters
  42.         jbe     _gttok1         ;loop if delimiter
  43.  
  44. ;--- read non-delimiters
  45.  
  46.         jmps    _gttok3         ;enter loop
  47.  
  48. _gttok2 cld
  49.         stosb                   ;store byte
  50.         push    cx
  51.         call    GetByt          ;read character
  52.         pop     cx
  53.         jc      _gttok5
  54.         cmp     al, 32          ;lower range of valid characters
  55.         jbe     _gttok6         ;exit loop if delimiter
  56.  
  57. _gttok3 loop    _gttok2         ;loop back if more bytes
  58.  
  59. ;--- token too long or read error
  60.  
  61.         sub     ax, ax          ;return zero if token too long
  62.  
  63. _gttok4 pop     cx              ;fix stack
  64.         pop     di
  65.         stc
  66.         ret
  67.  
  68. ;--- end of token
  69.  
  70. _gttok5 or      al, al          ;check if error
  71.         jnz     _gttok4         ;exit if so
  72.  
  73. _gttok6 sub     al, al          ;NUL
  74.         cld
  75.         stosb                   ;store it
  76.  
  77.         pop     ax              ;restore start address
  78.         sub     ax, di          ;get difference
  79.         neg     ax              ;adjust
  80.         dec     ax              ;don't count NUL
  81.  
  82.         pop     di
  83.         clc
  84.         ret
  85.         ENDP
  86.  
  87. _buffer4_end
  88.